import {Component} from 'react';
import http from '../utils/http';
class Headers extends Component{
    state={
        file:null,
        url:"",
        x:0,
        y:0,
    }
    render(){
        return(
            <div>
                <h1>设置http请求头</h1>
                <button onClick={()=>this.send()}>发送验证码</button>
                <button onClick={()=>this.Login()}>登录</button>
                <input type="file" onChange={(e)=>{
                    console.dir(e.target.files[0])
                    this.setState({
                        file:e.target.files[0]
                    })
                }}/>
                <button onClick={async ()=>{
                    // 数据流上传
                    // 创建fromData实例
                    let data = new FormData();
                    // 将文件对象信息添加到formData实例中
                    data.append("multipart",this.state.file);
                    // console.log(data.get("multipart"))
                    let res = await http(`/upload/image?model=maintain&pid=0`,'post',data,'multipart/form-data');
                    console.log(res)
                    this.setState({
                        url:res.data.data.url
                    })
                }}>上传头像</button>
                <img src={this.state.url} alt="" />
            </div>
        )
    }
    async send(){
        let res = await http(`/sendCode`,'post',{phone:15518835995},'application/x-www-form-urlencoded');
        console.log(res)
    }
    async Login(){
        let res = await http(`/login/mobile`,'post',{phone:15518835995,captcha:233508});
        console.log(res)
        localStorage.setItem("token",res.data.data.token)
    }
}
export default Headers;